<!-- 拼车送天府 -->
<template>
    <div style=" position: relative;">


        <!-- 搜索 -->
        <div style="display: flex;">
            <div>
                <el-date-picker :default-time="defaultTime" style="width: 340px;" v-model="timeTypeTime"
                    @change="timeTypeTime_btn" type="datetimerange" start-placeholder="开始时间" end-placeholder="结束时间"
                    format="YYYY-MM-DD HH:mm:ss" value-format="YYYY-MM-DD HH:mm:ss" />
            </div>


            <el-select clearable style="width:140px;margin-left: 10px;" v-model="find_data.follow"
                :placeholder="'订单状态'">
                <el-option :label="'未发布'" :value="'false'"></el-option>
                <el-option :label="'已发布'" :value="'true'"></el-option>
            </el-select>
            <el-input style="width: 180px;margin-left: 20px;" v-model="find_data.details" placeholder="订单详情搜索" clearable
                prefix-icon="Search" />
            <el-input  style="width: 160px;margin-left: 20px;" v-model="find_data.orderNum"
                placeholder="订单编号" clearable prefix-icon="Search" />

            <el-button style="margin-left: 20px;height:30px" @click="search_btn" type="primary"
                icon="Search">搜索</el-button>
            <el-button @click="up_btn" type="warning" icon="WarnTriangleFilled">修改</el-button>
            <el-button @click="del_btn" type="danger" icon="CircleCloseFilled">删除订单</el-button>
        </div>
        <!-- 功能按钮 -->


        <div style="margin-top: 10px;">
            <el-table border @selection-change="selection_change_btn" height="67vh" ref="multipleTableRef"
                :data="list_data" style="width: 100%" row-key="id"
                :tree-props="{ children: 'children', hasChildren: 'hasChildren' }">
                <el-table-column type="selection" width="35" />
                <el-table-column label="编号" width="55" fixed type="index" />
                <template v-for="item in table_data_list_new" :key="item.field">
                    <el-table-column v-if="item.off" :width="item.width" :prop="item.field" :label="item.label">
                        <template v-if="item.field == 'status'" #="{ row, column, $index }">
                            <span v-if="row.mergeId">
                                已发布
                            </span>
                            <span v-else style="color:red;">
                                未发布
                            </span>
                        </template>


                        <template v-if="item.field == 'routeSimpleName'" #="{ row, column, $index }">
                            <span v-if="row.isTrusteeOrder == 1">
                                <el-button circle  type="danger"
                                    size="small">托</el-button>
                            </span>
                            <span>{{
                                row.routeSimpleName }}</span>
                        </template>

                        <template v-if="item.field == 'needSeats'" #="{ row, column, $index }">
                            <span>{{ row.needSeats ? row.needSeats + '座' : '不限车型' }}</span>
                        </template>

                        <template v-if="item.field == 'driverName'" #="{ row, column, $index }">
                            <span>{{ row.driverName ? row.driverName + '-' + row.driverPhone : ''
                                }}</span>
                        </template>

                        <template v-if="item.field == 'startDate'" #="{ row, column, $index }">
                            <span>{{ row.startTime.split(' ')[0] }}</span>
                        </template>

                        <template v-if="item.field == 'startTime'" #="{ row, column, $index }">
                            <span>{{ row.startTime.split(' ')[1] }}</span>
                        </template>

                        <template v-if="item.field == 'endDate'" #="{ row, column, $index }">
                            <span>{{ row.endTime.split(' ')[0] }}</span>
                        </template>

                        <template v-if="item.field == 'endTime'" #="{ row, column, $index }">
                            <span>{{ row.endTime.split(' ')[1] }}</span>
                        </template>

                        <template v-if="item.field == 'cusName'" #="{ row, column, $index }">
                            <span>{{ row.cusInfo }}</span>
                        </template>

                        <template v-if="item.field == 'useCarCompanyId'" #="{ row, column, $index }">
                            <!-- row.realName ? row.realName  : -->
                            <!-- <span>{{
                    row.useCarCompanyName ? row.useCarCompanyName : row.mobile
                }}{{ row.mobile ? '-' + row.mobile : '' }}</span> -->
                            <span>{{ useCarCompanyId_data_api(row) }}</span>
                        </template>

                        <template v-if="item.field == 'useCarDutyInfo'" #="{ row, column, $index }">
                            <!-- <span>{{
                    row.useCarDutyInfo ? row.useCarDutyInfo.split('-').length > 2 ? row.useCarDutyInfo.split('-')[1] + '-' + row.useCarDutyInfo.split('-')[2] : row.useCarDutyInfo.split('-')[0] + '-' + row.useCarDutyInfo.split('-')[1]
                        : '' }}</span> -->
                            <span>{{ useCarDutyInfo_data_api(row) }}</span>
                        </template>
                        <!-- <template v-if="item.field == 'shareName'" #="{ row, column, $index }">
                        <span>{{ row.cusNam?row.cusName:'' }}-{{ row.shareMobile }}</span>
                    </template> -->
                        <template v-if="item.field == 'persons'" #="{ row, column, $index }">
                            <span>{{ row.serviceMan ? row.serviceMan.split('-')[1] + '-' + row.serviceMan.split('-')[2]
                                : '' }}</span>
                        </template>
                        <template v-if="item.field == 'isMerge'" #="{ row, column, $index }">
                            <span>{{ row.isMerge == true ? '合并' : '未合并' }}</span>
                        </template>
                    </el-table-column>

                </template>
                <el-table-column fixed="right" label="操作" width="180">
                    <template #default="{ row, column, $index }">
                        <div v-if="row.mergeId">
                            <!-- v-if='!row.mergeId' -->
                            <el-button type="danger" size="small" @click="no_release_btn(row)">取消发布</el-button>
                            <!-- <el-button type="warning" size="small" @click="no_hebing_Btn(row)">取消合并</el-button> -->
                        </div>
                        <div v-else>
                            <el-button type="primary" size="small" @click="release_btn(row)">发布</el-button>
                            <el-button v-if='row.index_off' type="warning" size="small"
                                @click="hebing_Btn(row)">合并发布</el-button>
                        </div>

                    </template>
                </el-table-column>

            </el-table>
        </div>

        <div style="margin-top:20px">
            <el-pagination @current-change="current_change_btn" @size-change="size_change_btn"
                v-model:current-page="find_data.page.pageNum" v-model:page-size="find_data.page.pageSize"
                :page-sizes="[100, 200, 300, 500]" :background="true" layout="prev, pager, next, jumper,->,sizes,total,"
                :total="total" />
        </div>

    </div>

    <!-- 弹窗 -->
    <div>
        <!-- 表格筛选 -->
        <div style="position: absolute;top:0px;z-index: 99999;" :style="icon_off ? 'right:50px;' : 'right:110px;'">
            <el-icon @click="icon_btn" :size="20">
                <Setting />
            </el-icon>
            <div v-show="icon_off"
                style=" position: fixed;top:100px;right:140px;width: 130px;height:430px;background:#fff;overflow: hidden;">
                <div class="cols-set" style="background:#fff;width:90%;height:97%;margin:auto;margin-top:10px;">
                    <div>
                        <el-button-group style="display: flex; ">
                            <el-tooltip effect="dark" placement="bottom">
                                <template #content>注意：拖动下面的项，可以改变表格列的顺序，<br />记得点击保存才会永久生效哦！ </template>
                                <el-button style="width:10px" type="primary" icon="WarningFilled"></el-button>
                            </el-tooltip>
                            <el-button title="重置" type="primary" icon="Refresh" @click="resetTableSet"></el-button>
                            <el-button title="保存" type="primary" icon="Check" @click="saveTableSet"></el-button>
                        </el-button-group>
                        <div ref="sortableContainer" class="col-items" style="height:400px; overflow-y: auto; ">
                            <el-checkbox class="drag_it" @change="checkbox_btn" v-for="item in sortedItems"
                                :key="item.field" v-model="item.off" :label="item.label" border>
                            </el-checkbox>
                        </div>

                    </div>
                </div>
            </div>
        </div>
        <uporder v-if="up_off" @myClick="upCarMd" :data="up_off" :id="up_id"></uporder>
        <!-- 合并发布 -->
        <el-dialog style="margin-top:5vh" v-model="hebing_Btn_off" title="合并发布" width="80%"
            :close-on-click-modal='false'>
            <div>



                <div v-for="(item, index) in hebing_Btn_data"
                    style="display:flex;margin-bottom:20px;font-weight:700;align-items: center;">
                    <b>{{ item.routeSimpleName }}</b>
                    <el-divider direction="vertical"></el-divider>
                    <b>{{ item.startTime }}</b>
                    <el-divider direction="vertical"></el-divider>
                    <b>{{ item.endTime }}</b>
                    <el-divider direction="vertical"></el-divider>
                    <el-tooltip effect="dark" :content="item.details" placement="bottom">
                        <b class="sl route-detail-text">{{ item.details }}</b>
                    </el-tooltip>
                    <el-divider direction="vertical"></el-divider>
                    <b>{{ item.personNum }}人</b>
                    <el-divider direction="vertical"></el-divider>
                    <b>{{ item.needSeats ? item.needSeats + '座' : '不限车型' }}</b>

                    <el-button v-if="index > 0" style="margin-left:10px" size="small" type="danger"
                        @click="set_over_btn(item)">删除</el-button>
                </div>

                <el-divider class="seled-order-line"><b style="color:blue;">订单</b></el-divider>

                <el-table :data="hebing_Btn_list" border fit :height="350" style="width: 100%;margin-bottom: 20px;">


                    <el-table-column label="编号" width="55" fixed type="index" />
                    <el-table-column width="120" property="set" label="操作">

                        <template #default="scope">
                            <el-button size="small" type="primary"
                                @click="hebing_Btn_list_btn(scope.row)">确认选择</el-button>
                        </template>
                    </el-table-column>
                    <el-table-column width="120" property="routeSimpleName" label="行程简称" />
                    <el-table-column width="220" label="驾驶员">

                        <template #="{ row, column, $index }">
                            <div v-if="row.plateNum">{{ row.plateNum }}（{{ row.driverName + '-' +
                                row.driverPhone
                                }}）</div>
                            <div v-else></div>
                        </template>

                    </el-table-column>
                    <el-table-column width="170" property="startTime" label="出发时间" />
                    <el-table-column property="fromLocation" label="出发地点" />
                    <el-table-column property="toLocation" label="结束地点" />
                    <el-table-column width="170" property="endTime" label="结束时间" />
                    <el-table-column width="120" property="lastDetails" label="人数">

                        <template #="{ row, column, $index }">
                            {{ row.personNum }}(人)
                        </template>
                    </el-table-column>
                    <el-table-column width="120" property="lastDetails" label="需求车型">

                        <template #="{ row, column, $index }">
                            {{ row.needSeats ? row.needSeats : '不限车型' }}
                        </template>
                    </el-table-column>
                    <el-table-column width="120" property="remark" label="备注" />


                </el-table>
                <div>

                    <el-button style="margin-left:90%" type="primary" @click="innerVisible_btn()">合并订单</el-button>
                </div>
            </div>
            <el-dialog v-model="innerVisible" title="合并订单时间选择:" width="30%" :close-on-click-modal='false'
                append-to-body>
                <div style="display: flex;">

                    <el-date-picker v-model="hebing_Btn_data_time" type="datetime" placeholder="请选择合并订单时间"
                        format="YYYY-MM-DD HH:mm:ss" value-format="YYYY-MM-DD HH:mm:ss" />
                    <el-input v-model="time_number1" @change='time_number_change1(1)'
                        style="width: 260px;margin-left:10px" placeholder="时间转换,格式:1201转换时间为12:01" clearable />
                </div>
                <el-button style="margin-left:85%;margin-top:10px" type="primary" @click="ok_over_btn()">确认</el-button>
            </el-dialog>

        </el-dialog>

    </div>
</template>

<script setup>
import Sortable from 'sortablejs';
import { ref, reactive, onMounted, computed } from 'vue'
import {
    line2treeData

} from '@/utils/common.js'

import {
    adupPrivateSet, getPrivateSetList, getOrderGroupCarList, release, cancelRelease, mergeQuerySend, merge,
    omsorderdelete,

} from '@/api/original_order_list.js'
// import uporder from './up.vue'
import uporder from './up/index.vue'
import { ElMessage, ElLoading, ElMessageBox } from 'element-plus'
import CircularJSON from 'circular-json'
onMounted(async () => {


    getPrivateSetList({
        find: '拼车送天府',
        page: {
            pageNum: 1,
            pageSize: 20,
        },
    }).then(res => {
        if (res.data.list[0]) {
            table_data_list_new.value = JSON.parse(res.data.list[res.data.list.length - 1].dat)
        } else {

            table_data_list_new.value = table_data_list
        }
    })



    Sortable.create(sortableContainer.value, {
        draggable: '.drag_it',
        ghostClass: 'sortable-ghost',
        onEnd: evt => {
            const targetRow = table_data_list_new.value.splice(evt.oldIndex, 1)[0];
            table_data_list_new.value.splice(evt.newIndex, 0, targetRow);

        }
    })




    timeTypeTime.value = [new_day(), to_day()]
    find_data.stime = new_day()
    find_data.etime = to_day()
    await list_api()

})
//#region 修改
const up_off = ref(false)
const up_id = ref('')
const up_btn = () => {
    if (table_list.value.length != 1) {
        return ElMessage({
            message: '请选择一条数据！',
            type: 'warning',
        })
    }
    if (table_list.value[0].isTrusteeOrder == 1) {
        return ElMessageBox.confirm(
            '该订单是托管单位订单不能修改和删除',
            {
                confirmButtonText: '确认',
                // cancelButtonText: '取消',
                type: 'warning',
                showCancelButton: false,
                distinguishCancelAndClose: 'true',
            }
        )
            .then(() => {

            })
            .catch((e) => {


            })
    }

    up_id.value = table_list.value[0].id
    up_off.value = true
}
const upCarMd = (e) => {
    list_api()
    up_off.value = false
}


//#endregion
//#region 删除
const del_btn = () => {
    if (table_list.value.length < 1) {
        return ElMessage({
            message: '请选择数据！',
            type: 'warning',
        })
    }

    if (table_list.value[0].isTrusteeOrder == 1) {
        return ElMessageBox.confirm(
            '该订单是托管单位订单不能修改和删除',
            {
                confirmButtonText: '确认',
                // cancelButtonText: '取消',
                type: 'warning',
                showCancelButton: false,
                distinguishCancelAndClose: 'true',
            }
        )
            .then(() => {

            })
            .catch((e) => {


            })
    }

    ElMessageBox.confirm(
        '是否确认删除订单?',
        {
            confirmButtonText: '确认',
            cancelButtonText: '取消',
            type: 'warning',
            distinguishCancelAndClose: 'true',
        }
    )
        .then(() => {
            let ps = []
            for (let i = 0; i < table_list.value.length; i++) {
                ps.push(table_list.value[i].id)
            }

            omsorderdelete({
                ids: ps
            }).then(res => {
                if (res.code == 1) {
                    list_api()
                    return ElMessage({
                        message: res.msg,
                        type: 'success',
                    })
                } else {
                    return ElMessage({
                        message: res.msg,
                        type: 'warning',
                    })
                }
            })
        })
        .catch((e) => {


        })

}
//#endregion
//#region 表格数据处理
const useCarDutyInfo_name = (e) => {
    // 1111
    let name = ''
    if (e) {
        let arr = e.split("-")
        if (arr.length > 2) {
            name = arr[1] + '-' + arr[2]
        } else {
            name = arr[0] + '-' + arr[1]
        }
    }

    return name
}
const table_data_list = reactive([
    { label: '行程简称', field: 'routeSimpleName', width: 120, off: true, },
    { label: '订单状态', field: 'status', width: 120, off: true, },

    { label: '人数', field: 'personNum', width: 120, off: true, },
    { label: '航班车次', field: 'flightNum', width: 120, off: true, },
    { label: '已派车辆', field: 'plateNum', width: 120, off: true, },
    { label: '驾驶员（电话）', field: 'driverName', width: 200, off: true, },
    { label: '出发日期', field: 'startDate', width: 120, off: true, },
    { label: '出发时间', field: 'startTime', width: 100, off: true, },
    { label: '到达日期', field: 'endDate', width: 120, off: true, },
    { label: '到达时间', field: 'endTime', width: 100, off: true, },
    { label: '行程详情', field: 'details', width: 600, off: true, },
    { label: '乘车人', field: 'cusName', width: 180, off: true, },
    { label: '订单价格', field: 'price', width: 100, off: true, },
    { label: '用车单位', field: 'useCarCompanyId', width: 220, off: true, },
    { label: '用车负责人', field: 'useCarDutyInfo', width: 220, off: true, },
    { label: '合并标记', field: 'isMerge', width: 100, off: true, },
    { label: '客户备注', field: 'remark', width: 600, off: true, },
    { label: '驾驶员备注', field: 'driverRemark', width: 700, off: true },
    { label: '业务员备注', field: 'serviceManRemark', width: 600, off: true, },
    { label: '业务员', field: 'persons', width: 160, off: true, },
    { label: '订单号', field: 'orderNum', width: 120, off: true, },
    { label: '添加时间', field: 'addTime', width: 170, off: true, },



])

const table_data_list_new = ref([])
const icon_off = ref(false)
// 创建排序容器的引用
const sortableContainer = ref('')

const icon_btn = () => {
    icon_off.value = !icon_off.value
    console.log(sortableContainer.value)

}
const resetTableSet = () => {

    table_data_list_new.value = JSON.parse(JSON.stringify(table_data_list))

}
const saveTableSet = () => {
    adupPrivateSet({
        dat: JSON.stringify(table_data_list_new.value),
        tbName: '拼车送天府',
        tbNum: "carpool_delivery",
    }).then(res => {
        if (res.code == 1) {
            return ElMessage({
                message: res.msg,
                type: 'success',
            })
        } else {
            return ElMessage({
                message: res.msg,
                type: 'warning',
            })
        }
    })
    icon_off.value = false
}

const checkbox_btn = (e, c) => {
    for (let i = 0; i < table_data_list_new.value.length; i++) {
        if (table_data_list_new.value[i].label == c.target._value) {
            table_data_list_new.value[i].off == e

        }

    }

}

const sortedItems = computed(() => {
    return [...table_data_list_new.value].sort((a, b) => a.id - b.id);
})
//#endregion


//#region 分页列表
const list_data = ref([])
const find_data = reactive({
    page: {
        pageNum: 1,
        pageSize: 100,
    },
    beReceived: '',
    follow: '',
    routeSimpleName: '拼车送天府',
    statusList: [],
    stime: '',
    etime: '',
    orderNum: '',
    details: '',
})
const total = ref(0)

// 分页器一夜显示多少数据页面
const size_change_btn = () => {
    find_data.page.pageNum = 1
    list_api()
}

// 分页器跳转页面
const current_change_btn = () => {
    list_api()
}
const useCarCompanyId_data_api = (e) => {
    let data = ''
    if (e.isCompanyCustomer == 1) {
        if (e.virtuallyUseCarInfo) {
            let data2 = ''
            if (e.useCarCompanyName) {
                data2 = e.useCarCompanyName ? e.useCarCompanyName : '匿名'
            } else {
                data2 = e.realName ? e.realName : '匿名'
            }
            data = e.virtuallyUseCarInfo.split('-')[0] + '【' + data2 + '】'
        } else {

            if (e.useCarCompanyName) {
                data = e.useCarCompanyName ? e.useCarCompanyName : '匿名'
            } else {
                data = e.realName ? e.realName : '匿名'
            }

        }
    } else if (e.isCompanyCustomer == 0 && e.companyNum == '8112010001') {
        if (e.virtuallyUseCarInfo) {
            let data2 = ''
            if (e.useCarCompanyName) {
                data2 = e.useCarCompanyName ? e.useCarCompanyName : '匿名'
            } else {
                data2 = e.realName ? e.realName : '匿名'
            }
            data = e.virtuallyUseCarInfo.split('-')[0] + '【' + data2 + '】'
        } else {

            if (e.useCarCompanyName) {
                data = e.useCarCompanyName ? e.useCarCompanyName : '匿名'
            } else {
                data = e.realName ? e.realName : '匿名'
            }

        }
    } else if (e.isCompanyCustomer == 0 && e.companyNum != '8112010001') {
        data = e.virtuallyUseCarInfo.split('-')[0] ? e.virtuallyUseCarInfo : '匿名'
    }


    return data
}
const useCarDutyInfo_data_api = (e) => {
    let data = ''
    if (e.isCompanyCustomer == 1) {

        if (e.virtuallyUseCarInfo) {
            let realName = e.realName ? e.realName : '匿名'
            let mobile = e.mobile ? e.mobile : ''
            data = e.virtuallyUseCarInfo.split('-')[0] + '(' + e.useCarDutyInfo+ ')'
        } else {
            let realName = e.realName ? e.realName : '匿名'
            let mobile = e.mobile ? e.mobile : ''
            data = e.useCarDutyInfo
        }

    } else if (e.isCompanyCustomer == 0 && e.companyNum == '8112010001') {

        if (e.virtuallyUseCarInfo) {
            let realName = e.realName ? e.realName : '匿名'
            let mobile = e.mobile ? e.mobile : ''
            data = e.virtuallyUseCarInfo.split('-')[0] + '(' + e.useCarDutyInfo + ')'
        } else {
            let realName = e.realName ? e.realName : '匿名'
            let mobile = e.mobile ? e.mobile : ''
            data = e.useCarDutyInfo
        }
    } else if (e.isCompanyCustomer == 0 && e.companyNum != '8112010001') {
        data = e.virtuallyUseCarInfo ? e.virtuallyUseCarInfo.split('-')[0] : '匿名'
    }


    return data


}

const list_api = () => {
    const loading = ElLoading.service({
        lock: true,
        text: '正在加载，中请稍后...',
        background: 'rgba(0, 0, 0, 0.7)',
    })
    getOrderGroupCarList(find_data).then(res => {
        loading.close()
        let data = res.data.list
        let index_no = 0
        for (let i = 0; i < res.data.list.length; i++) {
            if (index_no == 0 && res.data.list[i].mergeId == null) {
                res.data.list[i].index_off = true
            } else {
                res.data.list[i].index_off = false
            }
            if (res.data.list[i].mergeId == null) {
                index_no = 1
            }
        }

        list_data.value = data

        total.value = res.data.total

    })
}
//#endregion


//#region 表格选择
const table_list = ref([])
const selection_change_btn = (e) => {
    table_list.value = e
    console.log(e)
}
//#endregion

//#region 搜索
const search_btn = () => {

    list_api()
}
const new_day = () => {
    let today = new Date();

    let year = today.getFullYear();
    let month = today.getMonth() + 1; // 月份是从 0 到 11，所以需要加上 1
    let day = today.getDate();

    // 如果月份或日期小于 10，则在前面补零
    if (month < 10) {
        month = '0' + month;
    }

    if (day < 10) {
        day = '0' + day;
    }

    let formattedDate = `${year}-${month}-${day} 00:00:00`;
    return formattedDate
}
const to_day = () => {
    let today = new Date();
    let tomorrow = new Date(today);
    tomorrow.setDate(tomorrow.getDate() + 1);

    let year = tomorrow.getFullYear();
    let month = tomorrow.getMonth() + 1; // 月份是从 0 到 11，所以需要加上 1
    let day = tomorrow.getDate();

    // 如果月份或日期小于 10，则在前面补零
    if (month < 10) {
        month = '0' + month;
    }

    if (day < 10) {
        day = '0' + day;
    }

    let formattedDate = `${year}-${month}-${day} 23:59:59`;
    return formattedDate
}
const defaultTime = [new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 1, 1, 23, 59, 59)]

const timeTypeTime = ref([])
const timeTypeTime_btn = (e) => {
    if (e) {
        timeTypeTime.value = e
        find_data.stime = timeTypeTime.value[0]
        find_data.etime = timeTypeTime.value[1]
    } else {
        timeTypeTime.value = ''
        find_data.stime = ''
        find_data.etime = ''
    }
}
//#endregion

//#region 发布


const release_btn = (e) => {
    ElMessageBox.confirm(
        '确认发布订单?',
        {
            confirmButtonText: '确认',
            cancelButtonText: '取消',
            type: 'warning',
            distinguishCancelAndClose: 'true',
        }
    )
        .then(() => {


            release({ id: e.id }).then(res => {
                if (res.code == 1) {
                    list_api()

                    return ElMessage({
                        message: res.msg,
                        type: 'success',
                    })
                } else {
                    list_api()
                    return ElMessage({
                        message: res.msg,
                        type: 'warning',
                    })
                }
            })
        })
        .catch((e) => {


        })

}

const no_release_btn = (e) => {
    ElMessageBox.confirm(
        '取消发布订单?',
        {
            confirmButtonText: '确认',
            cancelButtonText: '取消',
            type: 'warning',
            distinguishCancelAndClose: 'true',
        }
    )
        .then(() => {


            cancelRelease({ id: e.id }).then(res => {
                if (res.code == 1) {
                    list_api()

                    return ElMessage({
                        message: res.msg,
                        type: 'success',
                    })
                } else {
                    list_api()
                    return ElMessage({
                        message: res.msg,
                        type: 'warning',
                    })
                }
            })
        })
        .catch((e) => {


        })
}

const hebing_Btn_off = ref(false)
const hebing_Btn_data = ref([])
const hebing_Btn_list = ref([])
const hebing_Btn = (e) => {
    hebing_Btn_data.value = []
    hebing_Btn_data.value.push(e)
    let ps = {
        id: e.id,
        notContainOrderId: [e.id],
    }
    mergeQuerySend(ps).then(res => {
        if (res.code == 1) {
            hebing_Btn_list.value = res.data
        } else {

            ElMessage({
                message: res.msg,
                type: 'warning',
            })
        }
    })
    hebing_Btn_off.value = true
}
const startTime_btn = (e) => {
    hebing_Btn_data_time.value = e
}
const hebing_Btn_list_btn = (e) => {
    if (hebing_Btn_data.value.length > 5) {
        return ElMessage({
            message: '最多合并5个订单',
            type: 'warning',
        })
    }
    hebing_Btn_data.value.push(e)
    let ps = {
        id: hebing_Btn_data.value[0].id,
        notContainOrderId: [],
    }
    for (let i = 0; i < hebing_Btn_data.value.length; i++) {
        ps.notContainOrderId.push(hebing_Btn_data.value[i].id)
        if (hebing_Btn_data_time.value) {
            let time1 = new Date(hebing_Btn_data_time.value).getTime()
            let time2 = new Date(hebing_Btn_data.value[i].startTime).getTime()
            if (time1 > time2) {
                hebing_Btn_data_time.value = hebing_Btn_data.value[i].startTime
            }

        } else {
            hebing_Btn_data_time.value = hebing_Btn_data.value[i].startTime
        }
    }
    mergeQuerySend(ps).then(res => {
        if (res.code == 1) {
            hebing_Btn_list.value = res.data
        } else {
            hebing_Btn_list.value = []
            ElMessage({
                message: res.msg,
                type: 'warning',
            })
        }
    })
}

const set_over_btn = (e) => {
    for (let i = 0; i < hebing_Btn_data.value.length; i++) {
        if (e.id == hebing_Btn_data.value[i].id) {
            hebing_Btn_data.value.splice(i, 1); // 删除一个元素
        }
    }
    let ps = {
        id: hebing_Btn_data.value[0].id,
        notContainOrderId: [],
    }
    for (let i = 0; i < hebing_Btn_data.value.length; i++) {
        ps.notContainOrderId.push(hebing_Btn_data.value[i].id)
    }
    mergeQuerySend(ps).then(res => {
        if (res.code == 1) {
            hebing_Btn_list.value = res.data
        } else {
            hebing_Btn_list.value = []
            ElMessage({
                message: res.msg,
                type: 'warning',
            })
        }
    })
}
const hebing_Btn_data_time = ref('')
const innerVisible = ref(false)
const innerVisible_btn = () => {
    if (hebing_Btn_data.value.length < 2) {
        return ElMessage({
            message: '请选择最少两个订单',
            type: 'warning',
        })
    }
    hebing_Btn_data_time.value = ''
    for (let i = 0; i < hebing_Btn_data.value.length; i++) {

        if (hebing_Btn_data_time.value) {
            let time1 = new Date(hebing_Btn_data_time.value).getTime()
            let time2 = new Date(hebing_Btn_data.value[i].startTime).getTime()
            if (time1 > time2) {
                hebing_Btn_data_time.value = hebing_Btn_data.value[i].startTime
            }

        } else {
            hebing_Btn_data_time.value = hebing_Btn_data.value[i].startTime
        }
    }

    innerVisible.value = true
}
const time_number1 = ref('')
const time_number_change1 = (e) => {
    // add_data.landDate转换
    if (!hebing_Btn_data_time.value) {
        time_number1.value = ''
        return ElMessage({
            message: '请先选择日期',
            type: 'warning',
        })
    } else if (time_number1.value.length != 4) {
        time_number1.value = ''
        return ElMessage({
            message: '时间格式不对，列12:01请输入1201',
            type: 'warning',
        })
    } else if (time_number1.value[0] > 2) {
        time_number1.value = ''
        return ElMessage({
            message: '时间格式不对，首数字不能大于2',
            type: 'warning',
        })
    } else if (time_number1.value[0] == 2) {
        if (time_number1.value[1] > 4) {
            time_number1.value = ''
            return ElMessage({
                message: '时间格式不对，列12:01请输入1201',
                type: 'warning',
            })
        }

    }
    let datetime1 = hebing_Btn_data_time.value.split(' ')[0]
    let datetime2 = time_number1.value[0] + time_number1.value[1] + ':' + time_number1.value[2] + time_number1.value[3] + ':00'
    hebing_Btn_data_time.value = datetime1 + ' ' + datetime2
    console.log(hebing_Btn_data_time.value)
    time_number1.value = ''
}

const ok_over_btn = () => {



    ElMessageBox.confirm(
        '是否确认合并订单?',
        {
            confirmButtonText: '确认',
            cancelButtonText: '取消',
            type: 'warning',
            distinguishCancelAndClose: 'true',
        }
    )
        .then(() => {
            let ps = {
                ids: [],
                startTime: '',
            }
            for (let i = 0; i < hebing_Btn_data.value.length; i++) {
                ps.ids.push(hebing_Btn_data.value[i].id)
                // if (ps.startTime) {
                //     let time1 = new Date(ps.startTime).getTime()
                //     let time2 = new Date(hebing_Btn_data.value[i].startTime).getTime()
                //     if (time1 > time2) {
                //         ps.startTime = hebing_Btn_data.value[i].startTime
                //     }

                // } else {
                //     ps.startTime = hebing_Btn_data.value[i].startTime
                // }
            }
            ps.startTime = hebing_Btn_data_time.value

            merge(ps).then(res => {
                if (res.code == 1) {
                    list_api()
                    hebing_Btn_off.value = false
                    innerVisible.value = false

                    return ElMessage({
                        message: res.msg,
                        type: 'success',
                    })
                } else {

                    return ElMessage({
                        message: res.msg,
                        type: 'warning',
                    })
                }
            })


        })
        .catch((e) => {


        })
}
//#endregion

</script>

<style scoped lang='scss'>
.paddingLeft {
    padding-left: 24px;
}

.paddingLeft_3 {
    padding-left: 48px;
}
</style>

<style>
.col-items::-webkit-scrollbar {
    width: 5px !important;
}

.col-items>label {
    margin-left: 0px !important;
    margin-top: 5px;
    width: 100%;
}


.el-table .el-table__cell {
    padding: 0px !important;
}
</style>
